package Game;

import java.util.ArrayList;

import Levels.Level1;
import Levels.LevelLoader;
import Levels.Objects;
import LifeForms.Chaser;

public class Movement {
	public void movement(Dude character,Character images,boolean left,boolean right,boolean up,boolean down,int lastpressedxy,int lastpressedx,int lastpressedy,IndexCounter index){
		if(!down&&!up&&!right&&!left){			
			if(lastpressedx==1&&lastpressedxy==1){
				index.setCounter(images.LinkStandingLeftArray.size(),0);
				character.setSprite(images.LinkStandingLeft,1);
			}
			if(lastpressedy==1&&lastpressedxy==2){
				index.setCounter(images.LinkStandingUpArray.size(),0);
				character.setSprite(images.LinkStandingUp,1);
			}
			if(lastpressedx==2&&lastpressedxy==1){
				index.setCounter(images.LinkStandingRightArray.size(),0);
				character.setSprite(images.LinkStandingRight,1);
			}
			if(lastpressedy==2&&lastpressedxy==2){
				index.setCounter(images.LinkStandingDownArray.size(),0);
				character.setSprite(images.LinkStandingDown,1);
			}
		}
		if(!left&&!right){
			character.setHorMove(0);
		}
		if(!up&&!down){
			character.setVerMove(0);
		}
		if(up||down){
			if(up&&lastpressedy==1){
				character.setVerMove(-1);
				if(character.ID!=images.LinkWalkingUp.getID()){
					index.setCounter(images.LinkWalkingUpArray.size()-1,10);
					character.setSprite(images.LinkWalkingUp,images.LinkStandingUp.getID());
				}
			}
			if(down&&lastpressedy==2){
				character.setVerMove(1);
				if(character.ID!=images.LinkWalkingDown.getID()){
					index.setCounter(images.LinkWalkingDownArray.size()-1,10);
					character.setSprite(images.LinkWalkingDown,images.LinkStandingDown.getID());
				}
			}
		}
		if(left||right){
			if(right&&lastpressedx==2){
				character.setHorMove(1);
				if(character.ID!=images.LinkWalkingRight.getID()){
					index.setCounter(images.LinkWalkingRightArray.size()-1,10);
					character.setSprite(images.LinkWalkingRight,images.LinkStandingRight.getID());
				}
			}
			if(left&&lastpressedx==1){
				character.setHorMove(-1);
				if(character.ID!=images.LinkWalkingLeft.getID()){
					index.setCounter(images.LinkWalkingLeftArray.size()-1,10);
					character.setSprite(images.LinkWalkingLeft,images.LinkStandingLeft.getID());
				}
			}
		}
	}
	boolean spaceDelay=false;
	public void actions(Dude character,boolean spaceBar,ArrayList<Projectile> projectiles,Sprite bulletSprite,int x,int y){
		if(spaceBar&&!spaceDelay){
			spaceDelay=true;
			character.fire(projectiles,bulletSprite,x,y);
		}else if(!spaceBar&&spaceDelay){
			spaceDelay=false;
		}
	}
	public void createbat(){
		Chaser chaser=new Chaser(Objects.batSprite, 0,Mainth.level.getLevel().getX(),Mainth.level.getLevel().getY());
		Mainth.level.getLevel().chasers.add(chaser);
	}
}
